/* eslint-disable no-const-assign */
import Vue from 'vue';

import 'normalize.css/normalize.css'; // A modern alternative to CSS resets
import './assets/iconfont/iconfont.css' // 首页字体图标

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import locale from 'element-ui/lib/locale/lang/zh-CN'; // lang i18n
import '@/styles/index.scss'; // global css

import App from './App';
import store from './store';
import router from './router';

import '@/icons'; // icon
import '@/permission'; // permission control

import Enum from 'vue-enum';
import enumInfo from './common/enum';

import JsonExcel from 'vue-json-excel'

import moment from 'moment/moment'
import '@/utils/loadmore.js'


// 注册滚动条加载触发事件v-loadmore绑定
// import loadmore from './loadmore'
Vue.prototype.$moment = moment;//赋值使用
Vue.component('downloadExcel', JsonExcel)
Vue.use(Enum, { enumInfo });
// Vue.use(loadmore)
console.log(store)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// 加载路由
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock');
//   mockXHR();
// }

// 加载列表数据
Vue.prototype.loadTableData = function (fn, black) {
  const that = this;
  that.loading = true;
  if (!black) black = [];
  let search_query = {}; // 搜索参数
  for (var elKey in that.query) {
    if (elKey === 'data') continue; // 判断返回数据
    if (black.findIndex(x => x === elKey) !== -1) continue;
    if (elKey === 'pageInfo') {
      search_query = that.query[elKey];
      continue;
    }
    search_query[elKey] = that.query[elKey];
  }
  // 获取列表数据
  return new Promise(() => {
    fn(search_query).then(res => {
      console.log('列表结果', res);
      const result = res.data.list;
      that.query.data = result; // 表格列表数据
      that.query.pageInfo.totalCount = res.data.total; // 分页显示用的总条数
      that.loading = false;
      that.$forceUpdate(); // 强制刷新
    });
  });
};

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI);

Vue.config.productionTip = false;

Vue.prototype.baseApi = process.env.VUE_APP_BASE_API;
Vue.prototype.baseUrl = process.env.VUE_APP_BASE_URL;


new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
});

export const base = process.env.VUE_APP_BASE_API;